package com.weixin.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/UserServlet/*")
public class UserServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		String info = request.getPathInfo().substring(1);
		if (info.equals("login")) {
			login(request,response);
		} else if (info.equals("listright")) {
			listright(request,response);
		}
	}

	private void listright(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// TODO Auto-generated method stub
		response.sendRedirect(request.getContextPath()+"/back/canting/right.jsp");
	}

	private void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// TODO Auto-generated method stub
		String name=request.getParameter("userid");
		String password=request.getParameter("pwd");
		if (name.equals("admin")&&password.equals("admin")) {
			response.sendRedirect(request.getContextPath()+"/index1.jsp");
			return ;
		}
		HttpSession session=request.getSession();
		boolean rs=false;
		/*List<User> yongList=us.queryUser();		
		for(int i=0;i<yongList.size();i++){
			User user=yongList.get(i);
			if(name.equals(user.getU_name())&&password.equals(user.getU_pass())){
				session.setAttribute("user", user);
				rs=true;
				break;
			}
		}*/
		if(rs){
			response.sendRedirect(request.getContextPath()+"/index1.jsp");
		} else{
			response.sendRedirect(request.getContextPath()+"/index.jsp");
		}
		
	}

 

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 doGet(request,response);
	}

}
